/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



//public void update_HashTableArray(ArrayList<Hashtable> new_HT_Array )
package Chat;

import java.util.*;
/**
 *
 * @author Wei Liang
 */
public class IpChat_Main {

    private static ArrayList<Hashtable> AL_HT = new ArrayList<Hashtable>();
  //  public static GUI_chat gui = new GUI_chat();
    private IpChat_Constructor callChat=null;

    public static String newIn=null;
    public static Boolean has_new_text=false;
    public static client.ClientView _clientView = null;

    //constructor 1
      public IpChat_Main(client.ClientView clientView)
      {
        System.out.println("\n");
        System.out.println("\n");
        System.out.println("\n");
        System.out.println("constructor at IpChat_Main(client.ClientView clientView)");
        System.out.println("No Hashtable is passed in..");
        System.out.println("\n");
        System.out.println("\n");
        System.out.println("\n");

            _clientView = clientView;
           develop();
      }

      private  void develop()
      { callChat= new IpChat_Constructor(AL_HT, this, _clientView);}

      // constructor 2
       public IpChat_Main(ArrayList<Hashtable> new_HT_Array, client.ClientView clientView)
      {


        System.out.println("\n");
        System.out.println("\n");
        System.out.println("\n");
        System.out.println("constructor: IpChat_Main(ArrayList<Hashtable> new_HT_Array, client.ClientView clientView)");
        System.out.println("\n");
        System.out.println("\n");
        System.out.println("\n");
           _clientView = clientView;
           callChat= new IpChat_Constructor(new_HT_Array, this, _clientView);
      }



    //<editor-fold desc="Methods">
     public static void sendT(String msgT)
     {   
        String temp = "T" + msgT;
        newIn=temp;
        has_new_text=true;
        System.out.flush();

        System.out.println("\n");
        System.out.println("\n");
        System.out.println("@IpChat_Main.sendT. New Text to send");
        System.out.println("@IpChat_Main.sendT  IpChat_Constructor.clientCount= "+ IpChat_Constructor.clientCount);
        System.out.println("@IpChat_Main.sendT  Message to send is: "+temp);
        System.out.println("@IpChat_Main.sendT  IpChat_Constructor.clients.size()= "+IpChat_Constructor.clients.size());
        if(IpChat_Constructor.clients.size() >0)
            for (int i=0;i < IpChat_Constructor.clients.size() ; i++)
                if(IpChat_Constructor.clients.get(i).Team.equals(ChatServer.ownTeamNumber) )
                   IpChat_Constructor.clients.get(i).newtext(temp);
        else
                System.out.println("Message not sent because client.size=0");
        System.out.println("\n");
        System.out.println("\n");
          
     }




    public static void sendA(String msgA)
    {
        String temp = "A" + msgA;
        newIn=temp;
        has_new_text=true;

        System.out.println("\n");
        System.out.println("\n");
        System.out.println("@IpChat_Main.sendA. New Text to send");
        System.out.println("@IpChat_Main.sendA. IpChat_Constructor.clientCount= "+ IpChat_Constructor.clientCount);
        System.out.println("@IpChat_Main.sendA Message to send is: "+temp);
        System.out.println("@IpChat_Main.sendA. IpChat_Constructor.clients.size()= "+IpChat_Constructor.clients.size());
        if(IpChat_Constructor.clients.size() >0)
            for (int i=0;i < IpChat_Constructor.clients.size() ; i++)
                IpChat_Constructor.clients.get(i).newtext(temp);
        else
            System.out.println("Message not sent because client.size=0");

        System.out.println("\n");
        System.out.println("\n");
    }



    public void update_HashTableArray(ArrayList<Hashtable> new_HT_Array )
    {
        callChat.checkunconnected();
        callChat.update_ht(new_HT_Array);
        callChat.checkunconnected();
    }


    
    public static void start()
    {
    
    }


}
